<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>              <!--2431010202--高宇鹏 -->
  <script>
    var str = '';
    var level = prompt('请输入金字塔的层数');
    level = parseInt(level) && Number(level);

    if (isNaN(level)) {
      alert('要求：纯数字');
    }
    for (var p = 1; p <= level; ++p) {
      var blank = level - i;
      for (var y = 0; y < blank; ++y) {
        str += ' ';
      }
      var star = i * 2 - 1;
      for (var g = 0; g < star; ++g) {
        str += '*';
      }
      str += '\n';
    }

    console.log(str);
  </script>  
</body>
</html>